<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import axios from 'axios'
import { API_BASE_URL, API_PATHS } from '@/api/config'

// 配置 axios 默认值
axios.defaults.baseURL = API_BASE_URL

interface Category {
  id: number
  name: string
  description: string
}

const loading = ref(false)
const categories = ref<Category[]>([])

// 获取分类列表
const fetchCategories = async () => {
  loading.value = true
  try {
    const response = await axios.get(API_PATHS.docs.categories)
    categories.value = response.data.data
  } catch (error) {
    ElMessage.error('获取分类列表失败')
    console.error('获取分类列表失败:', error)
  } finally {
    loading.value = false
  }
}

onMounted(() => {
  fetchCategories()
})
</script>

<template>
  <div class="docs-container">
    <el-card v-loading="loading">
      <template #header>
        <div class="card-header">
          <span>文档分类管理</span>
        </div>
      </template>
      
      <el-table :data="categories" style="width: 100%">
        <el-table-column prop="id" label="ID" width="80" />
        <el-table-column prop="name" label="分类名称" />
        <el-table-column prop="description" label="描述" />
      </el-table>
    </el-card>
  </div>
</template>

<style scoped>
.docs-container {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style> 